package com.amado.course09String;

import java.util.Scanner;

//int atmCount=0;
//String[][]atm=new String[100][4];
public class StringATMXT2 {
	public static void main(String[] args) {
		int atmCount = 0;
		String[][] atm = new String[100][4];
		atm[atmCount++] = new String[] { "111111", "111111", "1", "1000" };
		atm[atmCount++] = new String[] { "222222", "111112", "2", "2000" };
		atm[atmCount++] = new String[] { "333333", "111113", "3", "3000" };
		Scanner scanner = new Scanner(System.in);
		while (true) {
			System.out.println("1.管理员登录2.用户登录");
			int menuSelect = scanner.nextInt();
			if (menuSelect == 1) {
				System.out.println("请输入用户名");
				String userName = scanner.next();
				System.out.println("请输入密码");
				String password = scanner.next();
				if ("admin".equals(userName) && "admin".equals(password)) {
					System.out.println("1.办卡2.查看用户所有信息");
					menuSelect = scanner.nextInt();
					if (menuSelect == 1) {
						System.out.println("请输入卡号");
						int addcard = scanner.nextInt();
						boolean isExist = false;
						if (addcard > 99999 && addcard <= 999999) {
							for (int i = 0; i < atm.length; i++) {
								if (String.valueOf(addcard).equals(atm[i][0])) {
									isExist = true;
									break;
								}
							}
							if (isExist) {
								// 赋值
								System.out.println("卡号已存在");
							}
						} else {
							System.out.println("卡号不正确");
						}
						boolean passwordIsOk = false;
						if (!isExist) {
							System.out.println("请输入密码");
							int password1 = scanner.nextInt();
							if (password1 > 99999 && password1 <= 999999) {
								passwordIsOk = true;
								System.out.println("atmCount:" + atmCount);
								System.out.println("atmCount:" + atm[atmCount]);
								atm[atmCount][1] = String.valueOf(password1);
								System.out.println("密码以存在");
							} else {
								System.out.println("密码不正确");
							}
						}
						if (passwordIsOk) {
							System.out.println("请输入用户");
							int userName1 = scanner.nextInt();
							atm[atmCount][0] = String.valueOf(addcard);
							atm[atmCount][2] = String.valueOf(userName1);
							atm[atmCount][3] = String.valueOf(0);
							System.out.println("用户以增加");
							atmCount++;
						}
					}
				}
				if (menuSelect == 2) {
					for (int i = 0; i < atmCount; i++) {
						for (int j = 0; j < atm[i].length; j++) {
							System.out.print(atm[i][j] + "\t");
						}
						System.out.println();
					}
				}
			} else if (menuSelect == 2) {
				System.out.println("请输入用户名");
				String userName = scanner.next();
				System.out.println("请输入密码");
				String password = scanner.next();
				boolean isExist = true;
				int userlndex = -1;
				int count = 0;
				for (int i = 0; i < atmCount; i++) {
					if (userName.equals(atm[i][0]) && password.equals(atm[i][1])) {
						isExist = true;
						userlndex = i;
						System.out.println("用户跟密码匹配");
					}
				}
				if (isExist) {
					count++;
					if (count == 3) {
						System.out.println("密码输入超过三次");
					}
				} else {
					System.out.println("不正确");
					break;
				}
				while (userlndex != -1) {
					System.out.println("1.存款2.取款3.修改密码4.查询余额5.转账6.查询交易记录");
					menuSelect = scanner.nextInt();
					if (menuSelect == 1) {
						System.out.println("请输入一个存入金额");
						int newmoney = scanner.nextInt();
						if (newmoney % 100 == 0 && newmoney <= 10000) {
							//atm[userlndex][3] 当前余额
//							Integer.parseInt(atm[userlndex][3]) 转换为整型
//							Integer.parseInt(atm[userlndex][3])+newmoney int
							//String.valueOf(Integer.parseInt(atm[userlndex][3])+newmoney); 转换为String类型的
							atm[userlndex][3] = String.valueOf(Integer.parseInt(atm[userlndex][3])+newmoney);
							System.out.println("存入成功");
						} else {
							System.out.println("输入的金额不正确，请重新输入");
							break;
						}
					} else if (menuSelect == 2) {
						System.out.println("请输入取款金额");
						int fetchmoney = scanner.nextInt();
						int newmoney = scanner.nextInt();
						if (fetchmoney <= newmoney && newmoney % 100 == 0 && newmoney <= 10000) {
							System.out.println("取款成功");
						} else {
							System.out.println("取款金额错误，请重新输入");
						}
					} else if (menuSelect == 3) {// 修改密码
						System.out.println("请输入新密码");
						int onepassword = scanner.nextInt();
						int twopassword = scanner.nextInt();
						if (onepassword > 99999 && onepassword <= 999999) {
							System.out.println("请输入确定新密码");
							if (onepassword == twopassword) {
								System.out.println("修改密码成功");
							}
						} else {
							System.out.println("请输入6位数密码");
						}
					} else if (menuSelect == 4) {
						 System.out.println("当前金额 = "+atm[userlndex][3]);
					} else if (menuSelect == 5) {// 转账
						System.out.println("请输入要转入的卡号");
						int entercard = scanner.nextInt();
						int entercardlndex = -1;
						for (int i = 0; i < atmCount; i++) {
							if (entercard == atmCount && userName != userName) {
								System.out.println("用户名是");
							} else {
								System.out.println("请重新输入卡号");
							}
						}
						System.out.println("请输入转入金额");
						int entermoney = scanner.nextInt();
						int newmoney = scanner.nextInt();
						if (entermoney <= newmoney && entermoney % 100 == 0 && entermoney <= 10000) {
							System.out.println("转账成功");
						} else {
							System.out.println("请重新输入金额");
						}
					} else if (menuSelect == 6) {

					}
				}
			}
		}
	}
}
